<?php
declare (strict_types = 1);

namespace app\admin\controller;

use think\facade\Session;
use think\facade\Request;
use app\common\util\Upload as Up;
use app\common\model\AdminPhoto as P;
use app\common\service\AdminAdmin as S;
use app\common\model\DealMain as D_M;
use app\common\model\CustomerMain as CUS_M;


class Index extends Base
{
    protected $middleware = ['AdminCheck'];
    
    // 首页
    public function index(){
		
        return $this->fetch('',[
			'title' => '生华内部管理系统',
            'nickname'  => get_field('admin_admin',Session::get('admin.id'),'nickname')
        ]);
    }

    // 清除缓存
    public function cache(){
        Session::clear();
		F($this->uuid.'/collect/product',null);
		F($this->uuid.'/colth_list',null);
		F($this->uuid.'/ad',null);
		F($this->uuid.'/fragment',null);
		F($this->uuid.'/minApp/colth_class',null);
        return $this->getJson(rm());
    }

    // 菜单
    public function menu(){
        return json(get_tree(Session::get('admin.menu')));
    }

    // 欢迎页
    public function home(){
		$weekarray=["日","一","二","三","四","五","六"];
		$where="create_time >= ".strtotime(date('Y-m-d'))." and create_time<".(strtotime(date("Y-m-d",strtotime("+1 day")))).' and status=1';
		
		$d_total=0;
		$d_count=0;
		$d_volume=0;
		$d_customer=0;
		
		$card=[
			[
				'title'=>'我要下单',
				'icon'=>'add-1',
				'url'=>U('deal.main/add'),
			],
			[
				'title'=>'订单管理',
				'icon'=>'form',
				'url'=>U('deal.main/index'),
			],
			[
				'title'=>'色卡登记',
				'icon'=>'template-1',
				'url'=>U('customer.sample/add'),
			],
			[
				'title'=>'查找颜色',
				'icon'=>'theme',
				'url'=>U('cloth.color/find'),
			],
			[
				'title'=>'历史订单',
				'icon'=>'search',
				'url'=>U('deal.main/history'),
			],
			[
				'title'=>'产品差价表',
				'icon'=>'tabs',
				'url'=>U('cloth.main/cost'),
			],
			[
				'title'=>'销售统计',
				'icon'=>'chart-screen',
				'url'=>U('collect/sale'),
			],
			[
				'title'=>'话术管理',
				'icon'=>'dialogue',
				'url'=>U('quick.info/index'),
			],
			[
				'title'=>'图片管理',
				'icon'=>'picture',
				'url'=>U('admin.photo/index'),
			],
			[
				'title'=>'客户管理',
				'icon'=>'user',
				'url'=>U('customer.main/index'),
			],
			[
				'title'=>'收支管理',
				'icon'=>'rmb',
				'url'=>U('bill.main/index'),
			],
			[
				'title'=>'系统设置',
				'icon'=>'set-fill',
				'url'=>U('config/envSet'),
			],
		];
		
        return $this->fetch('',[
			'date'=>[
				'week'=>"星期".$weekarray[date("w",time())],
				'day'=>date("Y年m月d日"),
			],
			'd_total'=>$d_total,
			'd_count'=>$d_count,
			'd_volume'=>$d_volume,
			'd_customer'=>$d_customer,
			'system'=>$this->getSystem(),
			'card'=>$card,
		]);
    }

    // 修改密码
    public function pass(){
        if (Request::isAjax()){
            $this->getJson(S::goPass());
        }
        return $this->fetch();
    }

    // 通用上传
    public function upload(){
        return $this->getJson(Up::putFile(Request::file(),Request::post('path')));
    }
	
	// 抓取网上图片
	public function webPhoto(){
		$url=Request::post('url');
		$url=explode("\n",trim($url));
	    return $this->getJson(Up::getWebImages($url,Request::post('path')));
	}

    // 图库选择
    public function optPhoto(){
        if (Request::isAjax()) {
            return $this->getJson(P::getAll());
        }
        return $this->fetch('',P::getPath());
    }

}
